package display;
import java.io.*;
import java.util.*;

import controller.*;

import exception.UserSelectionOutOfRangeException;
public class Main {
	public static void main(String[] args) throws IOException{
		IOInput input = IOInput.getInputer();
		IOPrinter printer = IOPrinter.getPrinter();
        String filepathname = "src/file/MobilePhoneInformation.txt";

		try {
			Client site = Client.getSite();
			Scanner inFile = new Scanner(new File(filepathname));
			
			while(inFile.hasNext())
			{
				site.setUp(inFile.nextLine());
			}
			int userInput = -1;
			while(userInput!=0){
				try{
					site.generateMenu();
					userInput = Integer.parseInt(input.getInputNext());
					if(userInput!=0)
					{
						site.getUserSelection(userInput);
						printer.print("Input anykey to exit this function");
					}
					input.getInputNext();
					for(int i = 0 ; i<10 ;i++)
						printer.print("");
				}
				catch(NumberFormatException e){
					printer.print("You must only input number");
					for(int i = 0 ; i<2 ;i++)
						printer.print("");
				}
				catch (UserSelectionOutOfRangeException e) {
					printer.print(e.getMessage());
					for(int i = 0 ; i<2 ;i++)
						printer.print("");
				}
			}
			inFile.close();
		}	
			
		catch (FileNotFoundException e) {
			printer.print("Sorry, file not found. Please try a valid file path.");
		} 
	}
}
